package com.dashunwms_aohe.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dashunwms_aohe.bean.ds.*;
import com.dashunwms_aohe.http.DSHttpService;
import com.dashunwms_aohe.http.dto.*;
import com.dashunwms_aohe.http.res.GetDSDataRes;
import com.dashunwms_aohe.service.GetDSDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j(topic = "GetDSDataServiceImpl")
public class GetDSDataServiceImpl implements GetDSDataService {
    @Resource
    private DSHttpService dsHttpService;

    @Override
    public List<DS_InStockSHJLRes> getDS_InStockSHJL(GetDS_SHJLDto getDSShjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSShjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.SHJL_URL, JSON.toJSONString(jsonArray));
        List<DS_InStockSHJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_InStockSHJLRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_InStockSHJLRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("验收数据返回" + JSON.toJSONString(list));

        return list;
    }

    @Override
    public List<DS_InStockJSJLRes> getDS_InStockJSJL(GetDS_JSJLDto getDSJsjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSJsjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.JSJL_UR, JSON.toJSONString(jsonArray));
        List<DS_InStockJSJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_InStockJSJLRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_InStockJSJLRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("拒收记录返回" + JSON.toJSONString(list));

        return list;
    }

    @Override
    public List<DS_InStockYSJLRes> getDS_InStockYSJL(GetDS_YSJLDto getDSYsjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSYsjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.YSJL_URL, JSON.toJSONString(jsonArray));
        List<DS_InStockYSJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_InStockYSJLRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_InStockYSJLRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("采购验收记录返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_InStockXTYSJLRes> getDS_InStockXTYSJL(GetDS_XTYSJLDto getDSXtysjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSXtysjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.XTYSJL_URL, JSON.toJSONString(jsonArray));
        List<DS_InStockXTYSJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_InStockXTYSJLRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_InStockXTYSJLRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("销售退货验收记录返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_InStockBHGYSJLRes> getDS_InStockBHGYSJLR(GetDS_BHGYSJLDto getDSBhgysjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSBhgysjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.BHGYSJL_URL, JSON.toJSONString(jsonArray));
        List<DS_InStockBHGYSJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_InStockBHGYSJLRes> dsInStockBHGYSJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_InStockBHGYSJLRes.class);
            list.addAll(dsInStockBHGYSJLRes);
        }
        log.info("验收不合格数据返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_OutStockFHRes> getDS_OutStockFH(GetDS_CKFHDto getDSCkfhDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSCkfhDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.CKFH_URL, JSON.toJSONString(jsonArray));
        List<DS_OutStockFHRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_OutStockFHRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_OutStockFHRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("出库复核记录返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_JTOutStockJLRes> getDS_JTOutStockJL(GetDS_JTOutStockJLDto getDSJtOutStockJLDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSJtOutStockJLDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.JTOutStockJL_URL, JSON.toJSONString(jsonArray));
        List<DS_JTOutStockJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_JTOutStockJLRes> dsJtOutStockJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_JTOutStockJLRes.class);
            list.addAll(dsJtOutStockJLRes);
        }
        log.info("采购退货记录返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_WTYSJLRes> getDS_WTYSJLRes(GetDS_WTYSJLDto getDSWtysjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSWtysjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.WTYSJL_URL, JSON.toJSONString(jsonArray));
        List<DS_WTYSJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_WTYSJLRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_WTYSJLRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("委托运输记录返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_StockRes> getDS_Stock(GetDS_StockDto getDSStockDto) {
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.STOCK_URL, JSON.toJSONString(getDSStockDto));
        List<DS_StockRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_StockRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_StockRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("大舜库存返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_StockBHGRes> getDS_StockBHG(GetDS_StockBHGDto getDSStockBHGDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSStockBHGDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.STOCKBHG_RUL, JSON.toJSONString(jsonArray));
        List<DS_StockBHGRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_StockBHGRes> dsInStockSHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_StockBHGRes.class);
            list.addAll(dsInStockSHJLRes);
        }
        log.info("大舜不合格库存返回" + JSON.toJSONString(list));
        return list;
    }

    @Override
    public List<DS_StockYHJLRes> getDS_StockYHJL(GetDS_YHJLDto getDSYhjlDto) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(getDSYhjlDto);
        List<GetDSDataRes> getDSDataRes = dsHttpService.HttpPostReq_GetData(DS_Url.STOCKYHJL_URL, JSON.toJSONString(jsonArray));
        List<DS_StockYHJLRes> list = new ArrayList<>();
        for (GetDSDataRes getDSDataRe : getDSDataRes) {
            List<DS_StockYHJLRes> dsStockYHJLRes = JSONArray.parseArray(JSON.toJSONString(getDSDataRe.getInfo()), DS_StockYHJLRes.class);
            list.addAll(dsStockYHJLRes);
        }
        log.info("大舜在库商品养护返回" + JSON.toJSONString(list));
        return list;
    }
}
